package com.netclass.meethealth.tools;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

/**
 * 数据存储工具
 *
 * @author luodong 2015/12/28
 */
public class PreferenceManager {


    /**
     * 保存字符串数据
     *
     * @param context
     * @param str
     */
    public static void set(Context context, String str, String value) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("mh", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(str, value);
        editor.commit();
    }

    /**
     * 保存整数数据
     *
     * @param context
     * @param str
     */
    public static void set(Context context, String str, int value) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("mh", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putInt(str, value);
        editor.commit();
    }


    /**
     * 读取字符串
     *
     * @param context
     * @param str
     * @return
     */
    public static String getString(Context context, String str) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("mh", Context.MODE_PRIVATE);
        String value = sharedPreferences.getString(str, "");
        return value;
    }

    /**
     * 读取字符串
     *
     * @param context
     * @param str
     * @return
     */
    public static int getInt(Context context, String str) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("mh", Context.MODE_PRIVATE);
        int value = sharedPreferences.getInt(str, -1);
        return value;
    }

}
